﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace KELT.AutoColor
{
    public class ColorBoxItem
    {
        public StackPanel itemList;
        private Color[] m_colors;
        private string name;
        public bool isSelect = false;

        public Color[] colors
        {
            get
            {
                return m_colors;
            }
            set
            {
                m_colors = value;
            }
        }


        public ColorBoxItem(string name)
        {
            this.name = name;
        }
        public ColorBoxItem(string name, Color[] colors)
        {
            this.name = name;
            this.colors = colors;
        }

        public void CreateColorItem(ColorBoxManager boxManager, StackPanel panel)
        {
            TextBlock colorName = new TextBlock();
            colorName.Text = name;
            colorName.FontSize = 15;

            panel.Children.Add(colorName);
            panel.Children.Add(CreateColorBox(boxManager, colors));

            //byte[] colorBytes = new byte[3];
            //Color randomColor = Color.FromRgb(colorBytes[0], colorBytes[1], colorBytes[2]);
        }

        private StackPanel CreateColorBox(ColorBoxManager boxManager, Color[] color)
        {
            itemList = new StackPanel();
            itemList.Orientation = Orientation.Horizontal;
            itemList.HorizontalAlignment = HorizontalAlignment.Center;
            itemList.Margin = new Thickness(5);

            for (int i = 0; i < color.Length; i++)
            {
                itemList.Children.Add(CreateColorRectangle(color[i]));
            }

            itemList.MouseDown += new MouseButtonEventHandler(boxManager.selectItemBoxEvent);
            return itemList;
        }

        private Rectangle CreateColorRectangle(Color color)
        {

            Rectangle rect = new Rectangle();
            rect.Fill = new SolidColorBrush(color);
            rect.Width = 50;
            rect.Height = 50;

            return rect;
        }

    }
}
